package mhuu.view;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;

import mhuu.constant.AppConfig;
import mhuu.util.GZipUtils;

public class HttpResponsePanel extends JPanel{
	
	public HttpResponsePanel(){ 
		this.setBorder(BorderFactory.createLineBorder(Color.DARK_GRAY, 1));
		this.setPreferredSize(new Dimension(AppConfig.MainWindow_width/2, 500));
		this.setLayout(new BorderLayout());
		jPanel.setLayout(new BorderLayout());
		jPanel.add(jLabel,BorderLayout.WEST);
		jPanel.add(jButton,BorderLayout.EAST);
		this.add(jPanel,BorderLayout.NORTH);
		this.add(jScrollPane,BorderLayout.CENTER);
	}
	private JPanel jPanel=new JPanel();
	private JLabel jLabel=new JLabel("响应数据：");
	public static JButton jButton=new JButton("解密obj");{
		jButton.addActionListener(new ActionListener() {
			
			@Override
			public void actionPerformed(ActionEvent e) {
				String str=jTextArea.getText();
				String[] strArray=str.split("\n\n");
				String body=strArray[1];
				body=body.replaceAll("\\{", "");
				body=body.replaceAll("\\}", "");
				body=body.replaceAll("\"", "");
				String[] bodyArray=body.split(",");
				for (String string : bodyArray) {
					if (string.contains("obj")) {
						string=string.replaceAll("obj", "");
						string=string.replaceAll(":", "");
						string=string.replaceAll("\n","");
						string=string.replaceAll("\\n","");
						string=string.replaceAll("\\\n","");
						string=string.replaceAll("\\\\n","");
						string=string.trim();
						System.out.println(string);
						
						try {
							String jiemi=GZipUtils.decoderStr(string);
							JOptionPane.showMessageDialog(null, jiemi);
						} catch (Exception e1) { 
							e1.printStackTrace();
						}
						
					}
				}
				
			}
		});
	}
	public static JTextArea jTextArea=new JTextArea();{
		jTextArea.setLineWrap(true);
	}
	private JScrollPane jScrollPane = new JScrollPane(jTextArea); 
}
